package com.xq.mapper;


import com.xq.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

/**
 * @author xq
 * @date 2021/4/3 15:51
 * @version 1.0
 * @description 部门数据接口层
 */
public interface DeptMapper2 {

    /**
     * 根据部门Id查询部门信息
     * @param deptId
     * @return
     */
    @Select("select * from dept where dept_id = #{deptId} ;")
    @ResultMap("com.xq.mapper.DeptMapper.EmployeeResultMap")
    Dept getDeptByDeptId(Integer deptId);


    /**
     * 内连接查询，左表员工表，右边部门表，条件是部门ID   注解方式实现内连接 一对多
     * @return
     */
    @Select("select * from dept a inner join employee b on (a.dept_id = b.dept_id);")
    @Results({
            @Result(property = "deptId",column = "dept_id"),
            @Result(property = "deptName",column = "dept_name"),
            @Result(property = "deptLoc",column = "dept_loc"),
            @Result(property = "employeeSet",column = "dept_id", javaType = Set.class,
                    many = @Many(select = "com.xq.mapper.EmployeeMapper2.getEmployeesByDeptId")
            )
    })
    List<Dept> getAllByInJoinOnDeptIdCollectionAnnotation();
}
